﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace CommunitySystem.Map
{
	public partial class TipWindow : UserControl
	{
		public TipWindow()
		{
			// 为初始化变量所必需
			InitializeComponent();
			this.mainContent.Text = Title;
			
		}
		 public static readonly DependencyProperty TitleProperty =
            DependencyProperty.Register("Title", typeof(string), typeof(TipWindow), null);

        /// <summary>
        /// 获取或设置标题。
        /// </summary>
        public string Title
        {
            get { return (string)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
        }
        public void BindControl(Path uc)
        {
            this.mainContent.Text = Title;
            uc.MouseLeave += new MouseEventHandler(ti_MouseLeave);
            uc.MouseMove += new MouseEventHandler(ti_MouseMove);

        }
        public void CancelBindControl(Rectangle uc)
        {
            uc.MouseLeave -= new MouseEventHandler(ti_MouseLeave);
            uc.MouseMove -= new MouseEventHandler(ti_MouseMove);

        }
		/// <summary>
        /// 鼠标离开自定义控件时，隐藏提示框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ti_MouseLeave(object sender, MouseEventArgs e)
        {
            this.tip.IsOpen = false;
        }
        /// <summary>
        /// 鼠标在自定义控件上移动式时，提示框也跟随移动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ti_MouseMove(object sender, MouseEventArgs e)
        {
            this.tip.IsOpen = true;
            this.tip.HorizontalOffset = e.GetPosition(null).X - 52;
            this.tip.VerticalOffset = e.GetPosition(null).Y - 100;
        }
	}
}